<%@ page language="java" pageEncoding="UTF-8"%><!DOCTYPE html>
<html>
<head>
<title>新闻列表</title>
<jsp:include page="/admin/head.jsp"></jsp:include>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
</head>
<body>
	<jsp:include page="/admin/header.jsp"></jsp:include>
	<jsp:include page="/admin/left-menu.jsp?leftMenu=2"></jsp:include>
	<jsp:include page="/admin/footer.jsp"></jsp:include>

	<!-- BootstrapTable -->
	<script src="assets/plugins/bootstrap-table/bootstrap-table.min.js"
		type="text/javascript" charset="utf-8"></script>
	<script
		src="assets/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"
		type="text/javascript" charset="utf-8"></script>

	<!--中间-->
	<section>
		<nav aria-label="breadcrumb">
			<ol class="breadcrumb">
				<li class="breadcrumb-item">管理首页</li>
				<li class="breadcrumb-item">内容管理</li>
				<li class="breadcrumb-item active">新闻列表</li>
			</ol>
		</nav>

		<div class="pl-2 pr-2">
			<form class="form-inline keyForm">
				
				<div class="form-group mx-sm-1 mb-2">
					<label class="sr-only">关键字：</label> <input name="key" type="text"
						class="form-control" placeholder="搜索关键字">
				</div>
				
				<div class="form-group mx-sm-1 mb-2">
					<label class="sr-only">数量：</label> <select name="pageSize"
						class="form-control">
						<option value="5" ${page.rowMax==5?'selected':'' }>每页5条</option>
						<option value="10" ${page.rowMax==10?'selected':' ' }>每页10条</option>
						<option value="20" ${page.rowMax==20?'selected':' ' }>每页20条</option>
						<option value="50" ${page.rowMax==50?'selected':' ' }>每页50条</option>
					</select>
				</div>
				<button type="submit" class="btn btn-primary mb-2">
					<i class="fa fa-search"></i>
				</button>
			</form>

			<table class="table table-striped table-bordered table-hover">
				<thead>
					<tr>
						<th scope="col">#</th>
						<th scope="col">标题</th>
						<th scope="col">来源</th>
						<th scope="col">创建时间</th>
						<th scope="col">类别</th>
						<th scope="col">操作</th>
					</tr>
				</thead>

					<tbody id="xinwen">
				<c:forEach items="${page['list'] }" var="vo" varStatus="i">
						<tr>
							<th>${i.index+1 }</th>
							<td>${vo.articleTitle }</td>
							<td>${vo.articleWorker }</td>
							<td>${vo.articleTime }</td>
							<td>${vo.articleTypeName }</td>
							<td>
								<div class="dropdown">
									<button
										class="btn btn-outline-primary btn-block dropdown-toggle"
										type="button" data-toggle="dropdown">操作</button>
									<div class="dropdown-menu dropdown-menu-right">
										<a class="dropdown-item"
											href="admin-news-look.let?articleId=${vo.articleId }">查看</a> <a
											class="dropdown-item"
											href="admin-news-update-form.let?articleId=${vo.articleId }">修改</a>
										<a class="dropdown-item _delete"
											href="admin-news-delete.let?articleId=${vo.articleId }">删除</a>
									</div>
								</div>
							</td>
						</tr>
				</c:forEach>
					</tbody>


			</table>

		</div>
		<nav aria-label="Page navigation example">
			<ul class="pagination justify-content-center">
				<li class="page-item btn"><a class="page-link _start" aria-label="Previous">
				 <span aria-hidden="true">&laquo;</span>
				</a></li>
					<c:forEach items="${page.pages }" var="p" varStatus="i">
						<li class="page-item btn _page${p } ${p==page.current?'active':' '}"><a class="page-link"aria-label="Previous">
				 	<span aria-hidden="true">${p }</span>
					</a></li>
					</c:forEach>
				<li class="page-item btn"><a class="page-link _end" aria-label="Previous">
				 <span aria-hidden="true">&raquo;</span>
				</a></li>
			</ul>
		</nav>



	</section>
	<script type="text/javascript">
	var pageMax = ${page.pageMax };
	var pages = ${page.pages.size() };
	var curr = ${page.current };
	var st = ${page.pages[0] };
	console.info(st);
	var stt = ${page.pages[10] };
		//console.info(s);
		$("._start").click(function(){
			//console.info("yyyhhh");
			$("#xinwen").html("");
			$.post(
				"admin-article-page.let",
				{"current":1},
				function(data){
					//console.info("yyyhhh");
					console.info(data);
					$.each(data.list,function(i,obj){
						//console.info(obj);
						//console.info("obj.articleTitle:"${obj.articleTitle });
						let h = $("#xinwen").html();
						var tr = "<tr><th>"+(i+1)+"</th><td>"+obj.articleTitle +"</td><td>"+obj.articleWorker +"</td><td>"+obj.articleTime +"</td><td>"+obj.articleTypeName +"</td><td><div class='dropdown'><button class='btn btn-outline-primary btn-block dropdown-toggle' type='button' data-toggle='dropdown'>操作</button><div class='dropdown-menu dropdown-menu-right'><a class='dropdown-item' href='admin-news-look.let?articleId="+obj.articleId +"'>查看</a> <a class='dropdown-item' href='admin-news-update-form.let?articleId="+obj.articleId +"'>修改</a><a class='dropdown-item _delete' href='admin-news-delete.let?articleId="+obj.articleId +"'>删除</a></div></div></td></tr>";
						$("#xinwen").html(h+tr);
						console.info($("#xinwen"));
					})
					//window.location="admin-article-page1.let?current="+data.current;
				},"json"
			)
		});
		
		
		for(let i=st;i<=stt;i++){
			let cl = "._page"+i;
			console.info($(cl));
			$(cl).click(function(){
				//console.info("yyyhhh");
				$(cl).addClass("active").siblings().removeClass("active");
				$("#xinwen").html("");
				$.post(
					"admin-article-page.let",
					{"current":i},
					function(data){
						//console.info("yyyhhh");
						console.info(data);
						$.each(data.list,function(i,obj){
							//console.info(obj);
							//console.info("obj.articleTitle:"${obj.articleTitle });
							let h = $("#xinwen").html();
							var tr = "<tr><th>"+(i+1)+"</th><td>"+obj.articleTitle +"</td><td>"+obj.articleWorker +"</td><td>"+obj.articleTime +"</td><td>"+obj.articleTypeName +"</td><td><div class='dropdown'><button class='btn btn-outline-primary btn-block dropdown-toggle' type='button' data-toggle='dropdown'>操作</button><div class='dropdown-menu dropdown-menu-right'><a class='dropdown-item' href='admin-news-look.let?articleId="+obj.articleId +"'>查看</a> <a class='dropdown-item' href='admin-news-update-form.let?articleId="+obj.articleId +"'>修改</a><a class='dropdown-item _delete' href='admin-news-delete.let?articleId="+obj.articleId +"'>删除</a></div></div></td></tr>";
							$("#xinwen").html(h+tr);
							console.info($("#xinwen"));
						})
					},"json"
				)
				if(i>=stt-1){
					window.location="admin-article-page1.let?current="+i;
				}
				if(i<=st){
					window.location="admin-article-page1.let?current="+i;
				}
			});
		}
		
		$("._end").click(function(){
			//console.info("yyyhhh");
			$("#xinwen").html("");
			$.post(
				"admin-article-page.let",
				{"current":pageMax},
				function(data){
					//console.info("yyyhhh");
					console.info(data);
					$.each(data.list,function(i,obj){
						//console.info(obj);
						//console.info("obj.articleTitle:"${obj.articleTitle });
						let h = $("#xinwen").html();
						var tr = "<tr><th>"+(i+1)+"</th><td>"+obj.articleTitle +"</td><td>"+obj.articleWorker +"</td><td>"+obj.articleTime +"</td><td>"+obj.articleTypeName +"</td><td><div class='dropdown'><button class='btn btn-outline-primary btn-block dropdown-toggle' type='button' data-toggle='dropdown'>操作</button><div class='dropdown-menu dropdown-menu-right'><a class='dropdown-item' href='admin-news-look.let?articleId="+obj.articleId +"'>查看</a> <a class='dropdown-item' href='admin-news-update-form.let?articleId="+obj.articleId +"'>修改</a><a class='dropdown-item _delete' href='admin-news-delete.let?articleId="+obj.articleId +"'>删除</a></div></div></td></tr>";
						$("#xinwen").html(h+tr);
						console.info($("#xinwen"));
					})
					//window.location="admin-article-page1.let?current="+data.current;
				},"json"
			)
		});
		
		$("._delete").on("click", function() {
			console.info($(this).attr("href"));
			let href = $(this).attr("href")
			sys.confirm("您确定要删除这条记录吗？",function(r){
				if(r){
					$.get(
						href,
						function(data) {
							if (data.code == 200) {
								history.go(0);
								sys.toastr.success("删除成功");
							} else {
								sys.toastr.error(data.message);
							}
						}, "json"
					);
				}
			});
			return false;
		});
		
		
	</script>
</body>
</html>